var MapUtil = cc.Class({
    extends: cc.Component,

    properties: {
        elements: null,
    },

    // use this for initialization
    onLoad: function() {


    },
    init: function() {
        // console.log('MapUtil----------------------->:');
        this.elements = new Array();
    },
    //增加元素
    put: function(_key, _value) {
        var isExist = this.contains(_key);
        if (isExist) {
            this.remove(_key);
        }
        this.elements.push({
            key: _key,
            value: _value
        });
    },
    //获取元素
    get: function(_key) {
        try {
            for (i = 0; i < this.elements.length; i++) {
                if (this.elements[i].key == _key) {
                    return this.elements[i].value;
                }
            }
        } catch (e) {
            return null;
        }
    },
    //删除元素
    remove: function(_key) {
        var bln = false;
        try {
            for (i = 0; i < this.elements.length; i++) {
                if (this.elements[i].key == _key) {
                    this.elements.splice(i, 1);
                    return true;
                }
            }
        } catch (e) {
            bln = false;
        }
        return bln;
    },
    //是否存在该元素
    contains: function(_key) {
        var bln = false;
        try {
            for (i = 0; i < this.elements.length; i++) {
                if (this.elements[i].key == _key) {
                    bln = true;
                }
            }
        } catch (e) {
            bln = false;
        }
        return bln;
    },
    //获取map长度
    size: function() {
        return this.elements.length;
    },
    //map是否为空
    isEmpty: function() {
        return (this.elements.length < 1);
    },
    //清除所有元素
    clear: function() {
        this.elements = new Array();
    }
});